package com.example.demo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RecycleDemoActivity extends AppCompatActivity {
    private Context context;
    private List<App> apps = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_demo);


        RecyclerView recyclerView = findViewById(R.id.recycle_view);
        context = this;

        //1.指定表现形式
        //列表  目前是处于滚动
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        //实现水平滚动
        linearLayoutManager.setOrientation(linearLayoutManager.HORIZONTAL);


        //网格  这两种常用
        //GridLayoutManager gridLayoutManager = new GridLayoutManager(context,2);

        //指定形式
        recyclerView.setLayoutManager(linearLayoutManager);

        //2.自定义适配器
        MyAdapter myAdapter = new MyAdapter();
        recyclerView.setAdapter(myAdapter);







        //3.设置数据

        try {
            initData();
        } catch (IOException e) {
            e.printStackTrace();
        }
        myAdapter.setData(apps);

    }
    public void initData() throws IOException {

        //网络请求
//        Retrofit retrofit = new Retrofit.Builder()
//                .baseUrl("https://autumnfish.cn/api/")
//                .addConverterFactory(GsonConverterFactory.create())
//                .build();
//
//        JokesService service = retrofit.create(JokesService.class);
//
//        Call<JokesInfo> call = service.getJokes(20);
//        System.out.println(call);
//
//        //同步请求
//        try {
//            call.execute();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        //异步
//        call.enqueue(new Callback<JokesInfo>() {
//
//
//            @Override
//            public void onResponse(Call<JokesInfo> call, Response<JokesInfo> response) {
//                JokesInfo jokesInfo = response.body();
//                jokesInfos = jokesInfo;
//                System.out.println(jokesInfos);
//
//
//            }
//
//            @Override
//            public void onFailure(Call<JokesInfo> call, Throwable t) {
//
//            }
//        });

        for (int i = 0; i < 20; i++) {
            App app = new App();
            app.setName("5555");
            apps.add(app);
        }
    }

}













